package com.jf.cloud.service.sysmanager.common.base;

import org.apache.commons.lang.StringUtils;

import com.jf.cloud.service.sysmanager.common.db.SqlParse;
import com.jf.cloud.service.sysmanager.common.taglib.Paging;
import com.jf.cloud.service.sysmanager.common.util.BeanUtil;

/**
 * 分页对象
 * @param <T>
 * @author 卫江波
 * @2017年6月27日下午3:33:34
 */
public class OPaging<T> extends Paging<T> {
	private static final long serialVersionUID = 1L;
	/**
	 * ajax 分页的属性
	 */
	private int offset;
	
	private int limit;
	/**
	 * 排序 方式 
	 */
	private String  order;
	/**
	 * 排序 字段
	 */
	private String  sort;

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public Integer getOffset() {
		return offset;
	}

	public void setOffset(Integer offset) {
		this.offset = offset;
	}

	public Integer getLimit() {
		return limit>100?100:limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}
	
	public String getLimitStr() {
		return "limit "+getOffset()+","+getLimit(); 
	}
    /**
     * 重写 父类排序
     */
	public String getOrderBy() {
		if(StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)){
			  SqlParse.isRisk(sort);
			  String sortColnum = BeanUtil.propetyNameToColumnName(sort) ;
			  SqlParse.isRisk(order); 
			  return " order by "+sortColnum+" "+order+" "; 
		}
		return super.getOrderBy();
	}
	public String getOrderBy(boolean flag) {
		if(StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)){
			SqlParse.isRisk(sort);
			String sortColnum  = "";
			if(flag){
				sortColnum = BeanUtil.propetyNameToColumnName(sort) ;
			}else{
				sortColnum = sort;
			}
			SqlParse.isRisk(order); 
			return " order by "+sortColnum+" "+order+" "; 
		}
		return super.getOrderBy();
	}
	
	
	
	
}
